<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Proxy-set</title>
    <script>
        let obj = new Proxy({}, {
            set(target, prop, value) {
                // console.log(target, prop, value);
                if (prop == 'age') {
                    if (!Number.isInteger(value)) {
                        throw new TypeError('年龄必须为整数！！！');
                    }
                    if (value > 200) {
                        throw new RangeError('年龄超标，必须小于200岁！！！');
                    }
                }
                target[prop] = value;
            }
        });

        obj.a = 123;
        obj.name = 'Strive';

        console.log(obj);

        obj.age = 201;
    </script>
</head>

<body>

</body>

</html>